package com.dream.myqiyi.image.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

import com.dream.myqiyi.R;
import com.dream.myqiyi.image.model.Bucket;
import com.dream.myqiyi.image.model.Images;


/**
 * ƴͼѡ�����
 * @author admin
 *
 */
public class AlbumDetailActivity extends Activity{
	
	private Bucket bucket;
	//private Images imageChose;
	private TextView back;
	private GridView gridview;
	private GridViewAdapter gridViewAdapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);
		 setContentView(R.layout.image_album_detail);
		 Intent intent = getIntent();
		 if (intent.hasExtra("bundle")) {
			 Bundle bd = intent.getBundleExtra("bundle");
			 bucket = (Bucket) bd.getSerializable("bucket");
		 }
		 initUiData();
		 initListener();
	}
	
	public void initUiData() {
		
		back = (TextView) findViewById(R.id.back);
		gridview = (GridView)findViewById(R.id.chose_picture_grid);
		gridViewAdapter = new GridViewAdapter(this,bucket.getImages());
		gridview.setAdapter(gridViewAdapter);
		
	}
	public void initListener() {
		
		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {				
				Bundle bundle = new Bundle();
				bundle.putString("select_image", "");
				Intent intent = new Intent(AlbumDetailActivity.this, AlbumListActivity.class);
				intent.putExtras(bundle);
				
				AlbumDetailActivity.this.setResult(RESULT_OK, intent);		
				AlbumDetailActivity.this.finish();
			}
		});
				
		gridview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Images image = bucket.getImages().get(position);
				if(image != null) {
					// 选中一个图片跳转到note_view界面
					Bundle bundle = new Bundle();
					bundle.putString("select_image", image.get_data());
					Intent intent = new Intent(AlbumDetailActivity.this, AlbumListActivity.class);
					intent.putExtras(bundle);
					
					AlbumDetailActivity.this.setResult(RESULT_OK, intent);		
					AlbumDetailActivity.this.finish();
				}
			}
		});
	}
}
